package org.ims.inv.web.action.conference;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.ims.inv.model.conference.ModelConference;
import org.ims.inv.model.conference.ModelConferenceMaterial;
import org.ims.inv.model.system.ModelAppRole;
import org.ims.inv.model.system.ModelAppUser;
import org.ims.inv.model.system.ModelAppUserProfile;
import org.ims.inv.service.conference.ServiceConference;
import org.ims.inv.service.conference.ServiceConferenceEvent;
import org.ims.inv.service.conference.ServiceConferenceMaterial;
import org.ims.inv.web.action.BaseAppAction;
import org.ims.inv.web.util.ContextUtil;
import org.ims.inv.web.util.ExcelTemplateSupport;
import org.springframework.beans.BeanUtils;

import cn.trymore.core.util.UtilDate;
import cn.trymore.core.util.UtilFile;
import cn.trymore.core.util.UtilResources;
import cn.trymore.core.util.UtilString;
import cn.trymore.core.util.UtilZip;
import cn.trymore.core.vo.VoTplExcelObj;
import cn.trymore.core.web.paging.PaginationSupport;
import cn.trymore.core.web.paging.PagingBean;
import cn.trymore.oa.model.system.ModelFileAttach;

/**
 * Action: 会议管理
 * 
 * @author Jeccy.Zhao
 *
 */
public class ConferenceAction
extends BaseAppAction
{
	/**
	 * The LOGGER
	 */
	private static final Logger LOGGER = Logger.getLogger(ConferenceAction.class);
	
	/**
	 * The service of conference
	 */
	private ServiceConference serviceConference;
	
	/**
	 * The service of conference event
	 */
	private ServiceConferenceEvent serviceConferenceEvent;
	
	/**
	 * The service of conference material
	 */
	private ServiceConferenceMaterial serviceConferenceMaterial;
	
	/**
	 * The file upload destination path.
	 */
	private String uploadPath = "";
	
	/**
	 * The file upload temporary path.
	 */
	private String tempPath = "";
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议申请页面
	 */
	public ActionForward pageConferenceForm (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			ModelAppUser account = ContextUtil.getCurrentUser();
			ModelAppUserProfile profile = this.serviceAppUserProfile.findProfileByAccount(account.getId());
			
			request.setAttribute("account", account);
			request.setAttribute("profile", profile);
			request.setAttribute("applyTime", new Date());
			
			return mapping.findForward("page.conference.apply");
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议弹框页面
	 */
	public ActionForward dialogConferencePage (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String id = request.getParameter("id");
			if (this.isObjectIdValid(id))
			{
				ModelConference entity = this.serviceConference.get(id);
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在, ID-" + id));
				}
				
				request.setAttribute("entity", entity);
				request.setAttribute("applyTime", entity.getApplyTime());
				request.setAttribute("profile", 
						this.serviceAppUserProfile.findProfileByAccount(entity.getApplicant().getId()));
				request.setAttribute("attendees", 
						this.converseUidsToObject(entity.getAttendeeIds(), ","));
				
				this.outWriteAllParameters(request);
				
				return mapping.findForward("dialog.conference.page");
			}
			else
			{
				return ajaxPrint(response, getErrorCallback("数据ID不合法: " + id));
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 打包材料并下载
	 */
	public ActionForward actionPackMaterail (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String conferenceId = request.getParameter("id");
			if (this.isObjectIdValid(conferenceId))
			{
				ModelConference conference = this.serviceConference.get(conferenceId);
				if (conference != null)
				{
					String fileName = conference.getTitle() + ".zip";
					
					// 归类打包
					String archivePath = packConferenceMaterials (conference, request);
					
					// 生成zip文件
					UtilZip zip = new UtilZip(archivePath + ".zip");
					zip.compress(archivePath);
					
					if (archivePath != null)
					{
						//  写流文件到前端浏览器    
						ServletOutputStream out = response.getOutputStream();
						
						response.setHeader("Content-disposition", "attachment;filename=" + 
								new String(fileName.getBytes("gb2312"), "ISO8859-1" ));
						
						BufferedInputStream bis = null;
						BufferedOutputStream bos = null;
						try 
						{
							bis = new BufferedInputStream(new FileInputStream(archivePath + ".zip"));
							bos = new BufferedOutputStream(out);
							byte[] buff = new byte[2048];
							int bytesRead;
							while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) 
							{
								bos.write(buff, 0, bytesRead);
							}
						} 
						catch (IOException e) 
						{
							throw e;
						} 
						finally 
						{
							if (bis != null) 
							{
								bis.close();
							}
							if (bos != null) 
							{
								bos.close();
							}
						}
					}
				}
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when packing materials..", e);
		}
			
		return null;
	}
	
	/**
	 * 项目材料打包
	 * 
	 * @param project
	 * @return
	 */
	private String packConferenceMaterials (ModelConference conference, HttpServletRequest request)
	{
		if (conference != null)
		{
			// 归类
			@SuppressWarnings("deprecation")
			String uploadPath = request.getRealPath("/uploads/");
			String archivePath = uploadPath + "/archive/" + conference.getTitle() + 
				"_" + UtilDate.parseTime(new Date(), "yyyyMMddHHmm");
			
			UtilFile.createFolder(archivePath);
			
			if (conference.getMaterials() != null)
			{
				for (ModelConferenceMaterial material : conference.getMaterials())
				{
					if (material.getFileAttah() != null)
					{
						try
						{
							UtilFile.copyFile(
									new File(uploadPath + "/" + material.getFileAttah().getFilePath()), 
									new File(archivePath + "/" + material.getFileAttah().getFileName())
							);
						}
						catch (Exception e)
						{
							LOGGER.error("Exception raised when copying file," + 
									material.getFileAttah().getFilePath(), e);
						}
					}
				}
			}
			return archivePath;
		}
		return null;
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议资料页面
	 */
	public ActionForward dialogConferenceMaterial (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String id = request.getParameter("id");
			if (this.isObjectIdValid(id))
			{
				ModelConference entity = this.serviceConference.get(id);
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在, ID-" + id));
				}
				
				request.setAttribute("entity", entity);
				
				this.outWriteAllParameters(request);
				return mapping.findForward("dialog.conference.material");
			}
			else
			{
				return ajaxPrint(response, getErrorCallback("数据ID不合法: " + id));
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议资料上传页面
	 */
	public ActionForward dialogConferenceFileUpload (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String id = request.getParameter("id");
			if (this.isObjectIdValid(id))
			{
				ModelConference entity = this.serviceConference.get(id);
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在, ID-" + id));
				}
				
				request.setAttribute("entity", entity);
				
				this.outWriteAllParameters(request);
				return mapping.findForward("dialog.conference.material.upload");
			}
			else
			{
				return ajaxPrint(response, getErrorCallback("数据ID不合法: " + id));
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议资料上传页面
	 */
	public ActionForward actionRemoveConferenceMaterial (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String materialId = request.getParameter("id");
			if (this.isObjectIdValid(materialId))
			{
				ModelConferenceMaterial entity = this.serviceConferenceMaterial.get(materialId);
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在, ID-" + materialId));
				}
				
				// 解除关系
				ModelConference conference = entity.getConference();
				Set<ModelConferenceMaterial> materials = conference.getMaterials();
				Iterator<ModelConferenceMaterial> itor = materials.iterator();
				while (itor.hasNext())
				{
					ModelConferenceMaterial item = itor.next();
					if (item.getId().equals(materialId))
					{
						itor.remove();
						this.serviceConferenceMaterial.remove(entity);
						break;
					}
				}
				this.serviceConference.save(conference);
				request.setAttribute("entity", conference);
				this.outWriteAllParameters(request);
				
				return ajaxPrint(response, 
						getSuccessCallback("会议资料移除成功.", CALLBACK_TYPE_CLOSE, CURRENT_NAVTABID, null, false));
			}
			else
			{
				return ajaxPrint(response, getErrorCallback("数据ID不合法: " + materialId));
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议资料上传页面
	 */
	public ActionForward actionSaveConferenceMaterial (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String id = request.getParameter("id");
			if (this.isObjectIdValid(id))
			{
				ModelConference entity = this.serviceConference.get(id);
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在, ID-" + id));
				}
				
				String fileId = request.getParameter("fid");
				ModelFileAttach fileAttach = this.serviceFileAttach.get(fileId);
				if (fileAttach == null)
				{
					return ajaxPrint(response, getErrorCallback("上传的文件数据不存在, ID-" + fileId));
				}
				
				ModelConferenceMaterial material = new ModelConferenceMaterial();
				material.setConference(entity);
				material.setCreationTime(new Date());
				material.setFileAttah(fileAttach);
				material.setStatus(1);
				material.setPoster(ContextUtil.getCurrentUser());
				
				this.serviceConferenceMaterial.save(material);
				
				// 更新关系
				Set<ModelConferenceMaterial> materials = entity.getMaterials();
				if (materials == null)
				{
					materials = new HashSet<ModelConferenceMaterial>();
				}
				materials.add(material);
				this.serviceConference.save(entity);
				
				request.setAttribute("entity", entity);
				this.outWriteAllParameters(request);
				
				return ajaxPrint(response, 
						getSuccessCallback("会议资料保存成功.", CALLBACK_TYPE_CLOSE, CURRENT_NAVTABID, null, false));
			}
			else
			{
				return ajaxPrint(response, getErrorCallback("数据ID不合法: " + id));
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议记录页面
	 */
	public ActionForward pageConferenceList (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			ModelConference formEntity = (ModelConference) form;
			String attendeeName = request.getParameter("attendee.username");
			formEntity.setAttendeeNames(attendeeName);
			
			String status = request.getParameter("status");
			if (!UtilString.isNotEmpty(status))
			{
				formEntity.setStatus(null);
			}
			
			if (request.getParameter("list") != null)
			{
				if ("audit".equals(request.getParameter("list")))
				{
					// 显示待审批的会议数据列表
					formEntity.setStatus(ModelConference.EConferenceStatus.AUDITING.getValue());
					
					if (!ContextUtil.getCurrentUser().isSuperUser())
					{
						if (request.getParameter("leader") != null)
						{
							formEntity.setLeaderAudit(1);
						}
						else
						{
							formEntity.setLeaderAudit(0);
						}
					}
				}
				else if ("material".equals(request.getParameter("list")))
				{
					// 显示已通过的会议数据列表
					formEntity.setStatus(ModelConference.EConferenceStatus.PASSED.getValue());
				}
			}
			
			PagingBean pagingBean = this.getPagingBean(request);
			PaginationSupport<ModelConference> pagingData = 
					this.serviceConference.getPagination(formEntity, pagingBean);
			
			this.outWriteAllParameters(request);
			this.outWritePagination(request, pagingBean, pagingData);
			
			request.setAttribute("datagrid", pagingData);
			request.setAttribute("attendeeName", attendeeName);
			
			return mapping.findForward("page.conference.list");
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 专家导出
	 */
	public ActionForward actionExportConference (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			initFolders();
			
			ModelConference formEntity = (ModelConference) form;
			String attendeeName = request.getParameter("attendee.username");
			formEntity.setAttendeeNames(attendeeName);
			
			PagingBean pagingBean = new PagingBean(1, 0);
			PaginationSupport<ModelConference> pagingData = 
				this.serviceConference.getPagination(formEntity, pagingBean);
			
			if (pagingData != null && pagingData.getItemCount() > 0)
			{
				VoTplExcelObj obj = ExcelTemplateSupport.getTplObjFromTplFile(
						ExcelTemplateSupport.XLS_TPL_PATH + "/excel.conference.xml", null);
				
				if (obj != null)
				{
					List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
					for (ModelConference entity : pagingData.getItems())
					{
						Map<String, Object> singleRow = new HashMap<String, Object>();
						singleRow.put("conference", entity);
						data.add(singleRow);
					}
					
					obj = ExcelTemplateSupport.fillTplData(obj, data, null);
					obj.setSheetName("会议信息列表");
					
					String fileName = "exportConference_" + UtilDate.parseTime(new Date(), "yyyyMMddHHmmssSS") + ".xls";
					ExcelTemplateSupport.createExcel(this.tempPath + "/" + fileName, obj);
					
					return ajaxPrint(response, "{status:200, file:'" + "temp/" + fileName + "', name:'" + fileName + "'}");
				}
				else
				{
					return ajaxPrint(response, "{status:500, message:'文件导出失败.'}");
				}
			}
			else
			{
				return ajaxPrint(response, "{status:500, message:'没有可导出的数据.'}");
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, "{status:500, message:'文件导出失败.'}");
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议审批
	 */
	public ActionForward actionAuditConference (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			String conferenceId = request.getParameter("id");
			if (this.isObjectIdValid(conferenceId))
			{
				ModelConference entity = this.serviceConference.get(conferenceId);
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在:" + conferenceId));
				}
				
				String auditState = request.getParameter("auditState");
				String auditComments = request.getParameter("auditComments");
				
				if (ModelConference.EConferenceStatus.PASSED.getValue().equals(Integer.valueOf(auditState)))
				{
					// 审批通过
					Integer auditEdit = entity.getLeaderAudit();
					if (auditEdit == null || auditEdit == 0)
					{
						// 部长审批
						String toLeader = request.getParameter("leaderAudit");
						if (toLeader != null)
						{
							// 提交至院领导审批
							entity.setLeaderAudit(1);
							entity.setStatus(ModelConference.EConferenceStatus.AUDITING.getValue());
							entity.setLeadershipMeto(auditComments);
							auditComments = auditComments + "(提交至院领导审批)";
						}
						else
						{
							entity.setLeaderAudit(null);
							entity.setStatus(Integer.valueOf(auditState));
							entity.setDeptMeto(auditComments);
						}
					}
					else
					{
						// 院领导审批
						entity.setStatus(Integer.valueOf(auditState));
						entity.setLeaderAudit(null);
						entity.setLeadershipMeto(auditComments);
					}
				}
				else if (ModelConference.EConferenceStatus.RETURNED.getValue().equals(Integer.valueOf(auditState)))
				{
					// 退回
					if (entity.getLeaderAudit() == 1)
					{
						// 当前为院领导退回
						entity.setLeaderAudit(0);
						entity.setStatus(ModelConference.EConferenceStatus.AUDITING.getValue());
						entity.setLeadershipMeto(auditComments);
						auditComments = auditComments + "(退回至部长审批)";
					}
					else
					{
						entity.setDeptMeto(auditComments);
						entity.setStatus(Integer.valueOf(auditState));
					}
				}
				else
				{
					entity.setLeaderAudit(null);
					entity.setStatus(Integer.valueOf(auditState));
					
					if (entity.getLeaderAudit() == 1)
					{
						entity.setLeadershipMeto(auditComments);
					}
					else
					{
						entity.setDeptMeto(auditComments);
					}
				}
				
				this.serviceConference.save(entity);
				this.serviceConferenceEvent.traceEvent(entity, "会议审批", auditComments, Integer.valueOf(auditState));
				
				if (entity.getLeaderAudit() != null && entity.getLeaderAudit().equals(1) && 
						ModelConference.EConferenceStatus.AUDITING.getValue().equals(entity.getStatus()))
				{
					// 服务器推送至客户端, 提醒所有项目院领导.
					this.getMessagePush().pushMessage(
						this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_LEADER),
						scriptMessageNotify, 
						"menu_item_conf_audit",
						1
					);
					
					// 服务器推送至客户端, 提醒所有项目部长.
					this.getMessagePush().pushMessage(
						this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_MASTER),
						scriptMessageNotify, 
						"menu_item_conf_audit",
						-1
					);
				}
				else if (ModelConference.EConferenceStatus.RETURNED.getValue().equals(Integer.valueOf(auditState)) && 
						ModelConference.EConferenceStatus.AUDITING.getValue().equals(entity.getStatus()))
				{
					// 服务器推送至客户端, 提醒所有项目院领导.
					this.getMessagePush().pushMessage(
						this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_LEADER),
						scriptMessageNotify, 
						"menu_item_conf_audit",
						-1
					);
					
					// 服务器推送至客户端, 提醒所有项目部长.
					this.getMessagePush().pushMessage(
						this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_MASTER),
						scriptMessageNotify, 
						"menu_item_conf_audit",
						1
					);
				}
				else
				{
					// 服务器推送至客户端, 提醒所有项目院领导.
					this.getMessagePush().pushMessage(
						this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_MASTER),
						scriptMessageNotify, 
						"menu_item_conf_audit",
						-1
					);
					
					this.getMessagePush().pushMessage(
						this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_LEADER),
						scriptMessageNotify, 
						"menu_item_conf_audit",
						-1
					);
				}
				
				return ajaxPrint(response, 
						getSuccessCallback("会议审批成功.", CALLBACK_TYPE_CLOSE, CURRENT_NAVTABID, null, false));
			}
			else
			{
				return ajaxPrint(response, getErrorCallback("非法数据ID:" + conferenceId));
			}
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * <b>[WebAction]</b> 
	 * <br/>
	 * 会议保存
	 */
	public ActionForward actionSaveConference (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		try
		{
			ModelConference formEntity = (ModelConference) form;
			ModelConference entity = null;
			
			boolean isEdit = this.isObjectIdValid(formEntity.getId());
			if (isEdit)
			{
				entity = this.serviceConference.get(formEntity.getId());
				if (entity == null)
				{
					return ajaxPrint(response, getErrorCallback("数据实体不存在, ID-" + formEntity.getId()));
				}
				
				BeanUtils.copyProperties(formEntity, entity, 
					new String[] {"applyTime", "applicant", "events", "creationTime", "time", "status", "materials"});
				
				if (entity.getStatus().equals(ModelConference.EConferenceStatus.RETURNED.getValue()))
				{
					// 退回 --> 重新提交审批
					entity.setStatus(ModelConference.EConferenceStatus.AUDITING.getValue());
				}
			}
			else
			{
				entity = formEntity;
				entity.setCreationTime(new Date());
				entity.setApplicant(ContextUtil.getCurrentUser());
				entity.setRecorderName(ContextUtil.getCurrentUser().getUsername());
				entity.setStatus(ModelConference.EConferenceStatus.AUDITING.getValue());
			}
			
			entity.setLeaderAudit(0);
			entity.setTime(UtilDate.toDate(request.getParameter("time"), "yyyy-MM-dd"));
			entity.setApplyTime(UtilDate.toDate(request.getParameter("applyTime"), "yyyy-MM-dd"));
			
			// 会议参与人
			Map<String, List<String>> paramAttendeeIds = this.getAllRequestParameters(
					request, new String[] {"conferenceAttendeeIds"});
			
			if (paramAttendeeIds != null && paramAttendeeIds.size() > 0)
			{
				List<String> attendeeIds = paramAttendeeIds.get("conferenceAttendeeIds");
				List<String> attendeeNames = null;
				for (String attendeeId : attendeeIds)
				{
					ModelAppUser attendee = this.serviceAppUser.get(attendeeId);
					if (attendee != null)
					{
						if (attendeeNames == null)
						{
							attendeeNames = new ArrayList<String>();
						}
						attendeeNames.add(attendee.getUsername());
					}
					else
					{
						LOGGER.warn("The attendee does not exist with id:" + attendeeId);
					}
				}
				
				entity.setAttendeeIds(UtilString.join(attendeeIds, ","));
				entity.setAttendeeNames(UtilString.join(attendeeNames, ","));
				
				attendeeIds = null;
				attendeeNames = null;
			}
			
			this.serviceConference.save(entity);
			this.serviceConferenceEvent.traceEvent(entity, 
					"会议申请", "提交会议申请..", ModelConference.EConferenceStatus.AUDITING.getValue());
			
			// 服务器推送至客户端, 提醒所有项目部长.
			this.getMessagePush().pushMessage(
				this.getAllUserIdsByRole(ModelAppRole.ROLE_PROJECT_MASTER),
				scriptMessageNotify, 
				"menu_item_conf_audit",
				1
			);
						
			return ajaxPrint(response, 
					getSuccessCallback("会议保存成功.", CALLBACK_TYPE_CLOSE, CURRENT_NAVTABID, null, false));
		}
		catch (Exception e)
		{
			LOGGER.error("Exception raised when loading page", e);
			return ajaxPrint(response, getErrorCallback("数据加载失败,原因:" + e.getMessage()));
		}
	}
	
	/**
	 * 初始化文件夹
	 */
	private void initFolders ()
	{
		this.uploadPath = UtilResources.getWebRootPath() + "uploads";
		
		File localFile = new File(this.uploadPath);
		if (!localFile.exists())
		{
			localFile.mkdirs();
		}
		
		this.tempPath = this.uploadPath + "/temp";
		File tmpFile = new File(this.tempPath);
		if (!tmpFile.exists())
		{
			tmpFile.mkdirs();
		}
	}
	
	public static Logger getLogger()
	{
		return LOGGER;
	}

	public ServiceConference getServiceConference()
	{
		return serviceConference;
	}

	public void setServiceConference(ServiceConference serviceConference)
	{
		this.serviceConference = serviceConference;
	}

	public ServiceConferenceEvent getServiceConferenceEvent()
	{
		return serviceConferenceEvent;
	}

	public void setServiceConferenceEvent(ServiceConferenceEvent serviceConferenceEvent)
	{
		this.serviceConferenceEvent = serviceConferenceEvent;
	}

	public ServiceConferenceMaterial getServiceConferenceMaterial()
	{
		return serviceConferenceMaterial;
	}

	public void setServiceConferenceMaterial(ServiceConferenceMaterial serviceConferenceMaterial)
	{
		this.serviceConferenceMaterial = serviceConferenceMaterial;
	}
}
